

<!DOCTYPE html>
<!--
  ~  +----------------------------------------------------------------------
  ~  | 草帽支付系统 [ WE CAN DO IT JUST THINK ]
  ~  +----------------------------------------------------------------------
  ~  | Copyright (c) 2018 http://www.iredcap.cn All rights reserved.
  ~  +----------------------------------------------------------------------
  ~  | Licensed ( https://www.apache.org/licenses/LICENSE-2.0 )
  ~  +----------------------------------------------------------------------
  ~  | Author: Brian Waring <BrianWaring98@gmail.com>
  ~  +----------------------------------------------------------------------
  -->

<html>
<head>
    <meta charset="utf-8">
    <title>小红帽科技|草帽聚合支付 - 角色授权</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/common/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
    <div class="layui-card-body layui-row layui-col-space10">
        <input name="id" value="{$id}" hidden readonly>
        <div class="layui-form-item">
            <label class="layui-form-label">选择权限</label>
            <div class="layui-input-block">
                <div id="app-auth-tree-list"></div>
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<div class="layui-input-block">-->
                <!--<button class="layui-btn" type="submit" lay-submit lay-filter="app-auth-tree-submit">提交</button>-->
                <!--<button class="layui-btn layui-btn-primary" type="reset">重置</button>-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="app-admin-user-role-submit" id="app-admin-user-role-submit" value="确认">
        </div>
    </div>
</div>

<script src="__STATIC__/common/layui/layui.js"></script>
<script>
    layui.config({
        base: '__STATIC__/common/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','authtree', 'form'], function(){
        var $ = layui.$
            ,form = layui.form
            ,authtree = layui.authtree;

        // 初始化数据
        $.ajax({
            url: '/admin/getAuthMenu?id=' + "<?php echo $id;?>",
            success: function(res) {

                var checkedKey = [];
                for (var i = 0; i <= res.data.checked.length; i++) {
                    checkedKey.push(parseInt(res.data.checked[i]));
                }
                var trees = authtree.listConvert(res.data.list, {
                    primaryKey: 'id'
                    ,startPid: 0
                    ,parentKey: 'pid'
                    ,nameKey: 'name'
                    ,valueKey: 'id'
                    ,checkedKey: checkedKey
                });

                // 渲染时传入渲染目标ID，树形结构数据（具体结构看样例，checked表示默认选中），以及input表单的名字
                authtree.render('#app-auth-tree-list', trees, {
                    inputname: 'rules[]'
                    , layfilter: 'lay-check-auth'
                    , openall: true
                    , autowidth: true
                });
            }
        });

    });
</script>
</body>
</html>